#!/bin/bash

if [ $# -lt 2 ]
then
    echo "请增加推送证书文件以及p12文件以便生成pem文件，格式如:$0 file1.cer file2.p12"
else
    cer=${1}
    p12=${2}
    if [ ${cer##*.} != "cer" ]
    then
        echo "请输入cer文件："
        read cer
    fi
    if [ ${p12##*.} != "p12" ]
    then
        echo "请输入p12文件："
        read p12
    fi
    if [ ${cer##*.} = "cer" -a ${p12##*.} = "p12" ] 
    then    
        openssl x509 -in ${cer} -inform der -out PushChatCert.pem
        openssl pkcs12 -nocerts -out PushChatKey.pem -in ${p12}
        cat PushChatCert.pem PushChatKey.pem > ck.pem
        rm -f PushChatCert.pem
        rm -f PushChatKey.pem
        echo "注意：已生成ck.pem文件，请您将它发给服务器人员进行测试，若有任何问题，请发邮件至sunfei_fish@sina.cn，非常感谢～"
    fi
fi
